﻿Imports System.Net

Public Class OfficerAttachOpen
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Dim attDt As DataTable = New DataTable
            attDt = BL.Officer.GetOfficerAttachById(Convert.ToDecimal(Request.QueryString("attachid")))
            'Response.Redirect(attDt.Rows(0).Item("ATTACH_FILE_PATH"))

            Dim path As String = attDt.Rows(0).Item("ATTACH_FILE_PATH")
            Dim client As New WebClient()
            Dim buffer As [Byte]() = client.DownloadData(path)

            Dim fileExt As String
            fileExt = System.IO.Path.GetExtension(path)
            fileExt = fileExt.ToUpper

            If buffer IsNot Nothing Then
                If fileExt = ".PDF" Then
                    Response.ContentType = "application/pdf"
                ElseIf fileExt = ".JPG" Then
                    Response.ContentType = "image/jpeg"
                ElseIf fileExt = ".GIF" Then
                    Response.ContentType = "image/gif"
                End If
                Response.AddHeader("content-length", buffer.Length.ToString())
                Response.BinaryWrite(buffer)
                Response.End()
            End If
        Catch ex As Exception

        End Try
    End Sub

End Class